package com.longcai.piaojia.dialog;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.longcai.piaojia.R;
import com.longcai.piaojia.util.MyToast;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.util.UtilApp;
import com.zcx.helper.util.UtilMatches;

/**
 * Created by Administrator on 2015/6/11.
 */
public abstract class RegisterDialog extends BaseDialog {

//    @BoundView(R.id.goods_info_register_ll) private LinearLayout goods_info_register_ll;

    private Context context;

    public RegisterDialog(Context context, int width, String title) {

        super(context);
        initView(width, title);

        this.context = context;
    }

    private void initView(int width, String title){

        setContentView(R.layout.dialog_goods_info_register);

        LinearLayout goods_info_register_ll = (LinearLayout) findViewById(R.id.goods_info_register_ll);

        TextView goods_info_register_tv = (TextView) findViewById(R.id.goods_info_register_tv);

        goods_info_register_tv.setText(title);

        final EditText goods_info_register_et = (EditText) findViewById(R.id.goods_info_register_et);

        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) goods_info_register_ll.getLayoutParams();
        layoutParams.width = width;
        goods_info_register_ll.setLayoutParams(layoutParams);

        View.OnClickListener listener = new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                switch (v.getId()){

                    case R.id.goods_info_register_submit_tv:

                        if(TextUtils.isEmpty(goods_info_register_et.getText().toString().trim())){

                            MyToast.show(context, context.getString(R.string.warning_please_fill_phone_text), Toast.LENGTH_SHORT);

                            return;

                        }else if(!UtilMatches.checkMobile(goods_info_register_et.getText().toString().trim())){


                            MyToast.show(context, context.getString(R.string.warning_please_fill_true_phone_text), Toast.LENGTH_SHORT);

                            return;

                        }

                        onSubmit(goods_info_register_et.getText().toString().trim());

                        break;

                }

                dismiss();

            }

        };

        findViewById(R.id.goods_info_register_submit_tv).setOnClickListener(listener);

    }

    protected abstract void onSubmit(String phone);

}
